<template>
  <div id="app">
    <img src="../assets/logo.png">
    <div>
      <h1>启迪面试系统</h1>
      <div id="login">

        <el-card class="box-card">
            <div slot="header" class="clearfix">
            <h2>用户登录 <router-link to="/regist" type="primary" class="regist">我要注册</router-link></h2>
            </div>
            <div class="text item">
              <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <el-form-item label="登录账号" prop="username">
                  <el-input type="text" v-model="ruleForm.username" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="登录密码" prop="userpass">
                  <el-input type="password" v-model="ruleForm.userpass" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="submitForm('ruleForm')">我要登录</el-button>
                  <el-button @click="resetForm('ruleForm')">重置</el-button>
                </el-form-item>
                </el-form>
            </div>
        </el-card>

        
      </div>
    </div>
  </div>
</template>

<script>
//import HelloWorld from './components/HelloWorld.vue'

export default {
  name: 'app',
  data() {
        var validateName = (rule, value, callback) => {
          if (value === '') {
            callback(new Error('请输入账号'));
          } else {
            callback();
          }
        };
        var validatePass = (rule, value, callback) => {
          if (value === '') {
            callback(new Error('请输入密码'));
          } else {
            callback();
          }
        };
        return {
          ruleForm: {
            username: '',
            userpass: ''
          },
          rules: {
            username: [
              { validator: validateName, trigger: 'blur' }
            ],
            userpass: [
              { validator: validatePass, trigger: 'blur' }
            ]
          }
        };
      },
      methods: {
        submitForm(formName) {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              //alert('submit!');
              this.$router.push("/home");
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        },
        resetForm(formName) {
          this.$refs[formName].resetFields();
        }
      }
  }
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

#login {
  width: 400px;
  margin: 0 auto;
}

.regist {
  font-size: 12px;
}
</style>
